package com.gf.gateway.common;

/**
 * @author gFly
 * @date 2024/1/12 15:39
 * @Describe
 */

public class CommonRTException extends RuntimeException implements StandardException {
    private String code;
    private Object[] args;

    public CommonRTException(String message) {
        super(message);
        this.code = CommonErrors.SYSTEM_ERROR.code();
    }

    public CommonRTException(String code, String message) {
        super(message);
        this.code = CommonErrors.SYSTEM_ERROR.code();
        this.code = code;
    }

    public CommonRTException(String message, Throwable cause) {
        super(message, cause);
        this.code = CommonErrors.SYSTEM_ERROR.code();
    }

    public CommonRTException(Throwable cause) {
        super(cause);
        this.code = CommonErrors.SYSTEM_ERROR.code();
    }

    public CommonRTException(StandardStringEnum cause, Object... objs) {
        super(cause.description(objs));
        this.code = CommonErrors.SYSTEM_ERROR.code();
        this.code = cause.code();
    }

    public String errorCode() {
        return this.code;
    }

    public Object[] args() {
        return this.args;
    }

    public String errorMessage() {
        return this.getMessage();
    }

    public static void buildByCommonErrors(CommonErrors commonErrors) {
        throw new CommonRTException(commonErrors.code(), commonErrors.description(new Object[0]));
    }

    public static void buildByArgs(String code, Object... args) {
        CommonRTException commonRTException = new CommonRTException();
        commonRTException.code = code;
        commonRTException.args = args;
        throw commonRTException;
    }

    public static void build(String code, String message) {
        throw new CommonRTException(code, message);
    }

    public CommonRTException() {
        this.code = CommonErrors.SYSTEM_ERROR.code();
    }
}
